const TokenKey = "access_token";
const appTokenKey = "app_access_token";
const DoorTokenKey = "door_access_token";
const curDepartmentKey = "cur_department";
const curCompanyKey = "cur_company";
const LoginType = "loginType";
const DoorLoginType = "doorLoginType";
const AppCompanyId = "app_comapny_id";

import store from "@/store";
import { isArray } from '@/utils/util.js'

const default_company_info = {
	name:'美莱文化',
	name_color: '#FFFFFF',
	logo: 'https://fuxing-haohujia-test1.oss-cn-shanghai.aliyuncs.com/20210517094931986208.jpg'
};


export function getToken() {
  return localStorage.getItem(TokenKey);
}

export function setToken(token) {
  return localStorage.setItem(TokenKey, token);
}

export function removeToken() {
  return localStorage.removeItem(TokenKey);
}

export function getAppToken() {
  return localStorage.getItem(appTokenKey);
}

export function setAppToken(token) {
  return localStorage.setItem(appTokenKey, token);
}

export function removeAppToken() {
  return localStorage.removeItem(appTokenKey);
}

export function getAppCompanyId() {
  return localStorage.getItem(AppCompanyId);
}

export function setAppCompanyId(companyId) {
  return localStorage.setItem(AppCompanyId, companyId);
}

export function removeAppCompanyId() {
  return localStorage.removeItem(AppCompanyId);
}

export function getDoorToken() {
  return localStorage.getItem(DoorTokenKey);
}

export function setDoorToken(token) {
  return localStorage.setItem(DoorTokenKey, token);
}

export function removeDoorToken() {
  return localStorage.removeItem(DoorTokenKey);
}

export function getCurDepartment() {
  return localStorage.getItem(curDepartmentKey);
}

export function setCurDepartment(cur_department) {
  return localStorage.setItem(curDepartmentKey, cur_department);
}

export function removeCurDepartment() {
  return localStorage.removeItem(curDepartmentKey);
}

export function getCurCompany() {
	let info = localStorage.getItem(curCompanyKey)
  return info?JSON.parse(info):default_company_info;
}

export function setCurCompany(cur_company) {
  return localStorage.setItem(curCompanyKey, JSON.stringify(cur_company));
}

export function removeCurCompany() {
  return localStorage.removeItem(curCompanyKey);
}

export function clearStorage() {
  // 移除所有
  return localStorage.clear();
}

export function setType(token) {
  return localStorage.setItem(LoginType, token);
}

export function getType() {
  return localStorage.getItem(LoginType);
}

export function setDoorType(token) {
  return localStorage.setItem(DoorLoginType, token);
}

export function getDoorType() {
  return localStorage.getItem(DoorLoginType);
}

export function checkBtnRight(rightName){
	const btnRights = store.getters && store.getters.btnRights
	let flag = false
	if(btnRights && isArray(btnRights) && btnRights.length > 0){
		btnRights.forEach(item => {
			if(''+item.name === ''+rightName) flag = true
		})
	}
	return flag
}
